package com.swp.oa.util;

import java.io.File;
import java.io.FilenameFilter;

/**
 * 定制文件名过滤器
 * @author Administrator
 *
 */
public class FileNameFilterEx implements FilenameFilter{

	private String[] filter = null;
	private boolean isName;
	
	/**
	 * 
	 * @param nameFilter 过滤器
	 * @param isName true=按名字过滤，false=按后缀过滤
	 */
	public FileNameFilterEx(String[] nameFilter, boolean isName){
		filter = nameFilter;
		this.isName = isName;
	}
	
	/**
	 * @return the filter
	 */
	public String[] getFilter() {
		return filter;
	}

	/**
	 * @param filter the filter to set
	 */
	public void setFilter(String[] filter) {
		this.filter = filter;
	}

	@Override
	public boolean accept(File dir, String name) {
		
		if (isName) {
			for (int i = 0; i < filter.length; i++) {
				if (name.equalsIgnoreCase(filter[i])) {
					return true;
				}
			}
		} else {
			for (int j = 0; j < filter.length; j++) {
				if (name.toLowerCase().endsWith(filter[j].toLowerCase())) {
					return true;
				}
			}
		}
		return false;
	}
} // end class
